# coding=utf-8

import os
from utils import fileutils


def read_config(envir, source_table, db):
    __FILE_PATH = os.path.abspath(__file__)
    __CURRENT_PATH = os.path.abspath(os.path.dirname(__FILE_PATH) + os.path.sep + ".")
    if db == 'test':
        __CONFIG_PATH = __CURRENT_PATH + os.sep + ".." + os.sep + "bin" + os.sep + source_table + "_staging_config.yaml"
    else:
        __CONFIG_PATH = __CURRENT_PATH + os.sep + ".." + os.sep + "bin" + os.sep + source_table + "_config.yaml"
    config = fileutils.get_yaml_config(__CONFIG_PATH)

    table_name = config['table_name']
    db_name = config['db_name']
    env = config['env']
    if source_table == table_name and db == db_name and envir == env:
        partition_date = config['partition_date']
        sample_ratio = config['sample_ratio']
        warn_email = config['warn_email']
        custom = config['custom']
        return table_name, db_name, env, partition_date, sample_ratio, warn_email, custom
    return
